using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;

namespace XNAProjectLibrary
{
    public abstract partial class GameState : DrawableGameComponent, IGameState
    {
        protected IGameStateManager GameManager;                                        //gamestate manager interface
        protected IInputHandler Input;                                                  //input manager interface
        protected Rectangle TitleSafeArea;                                              //titlesage area

        public GameState(Game game)
            : base(game)
        {
            GameManager = (IGameStateManager)game.Services.GetService(
                typeof(IGameStateManager));                                             //get gamemanager (gamemanager is "GLOBAL")
            Input = (IInputHandler)game.Services.GetService(
                typeof(IInputHandler));                                                 //get inputhandler (also "GLOBAL")
        }

        protected override void LoadContent()
        {
            TitleSafeArea = Utility.GetTitleSafeArea(GraphicsDevice, 0.85f);            //set up titlesage area
        }

        internal protected virtual void StateChanged(object sender, EventArgs e)        //state changed event??
        {
            if (GameManager.State == this.Value)                                        //toggle visibile/enabled if I was changed
                Visible = Enabled = true;
            else
                Visible = Enabled = false;
        }

        #region IGameState Members
        public GameState Value                                                          //returns selfpointer
        {                                                                               //needed for gamemanager's changestate
            get { return (this); }
        }
        #endregion
    }
}
